# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def removeNthFromEnd(self, head, n):
        """
        :type head: ListNode
        :type n: int
        :rtype: ListNode
        """
        if not head:
            return None
        l = f = head
        while n > 0:
            if f.next != 0:
                f = f.next
                n -= 1
            if not f:
                return head.next
        while f.next:
            f = f.next
            l = l.next
        p = l.next
        l.next = p.next
        return head


l1 = ListNode(1)
s = Solution()
m = s.removeNthFromEnd(l1,1)
print(m)